﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class HandlerDao:BaseDao
    {
        public Handler Handler { get; set; }

        public List<Handler> GetAllHandler()
        {
            var query = from c in _agiltasticDbEntities.Handler.Include("Club1")
                        orderby c.Name
                        select c;
            return query.ToList();
        }

        public Handler GetById(int id)
        {
            var query = from c in _agiltasticDbEntities.Handler
                        where c.Id == id
                        select c;
            return query.FirstOrDefault();
        }

        public void Update(Handler currentSelected)
        {
            var Handler = GetById(currentSelected.Id);
            Handler.Name = currentSelected.Name;
            Handler.FirstName = currentSelected.FirstName;
            Handler.LastName = currentSelected.LastName;
            Handler.Club = currentSelected.Club;
            Handler.ClubName = currentSelected.ClubName;
            _agiltasticDbEntities.SaveChanges();
        }

        public void Save(Handler currentSelected)
        {
            _agiltasticDbEntities.Handler.Add(currentSelected);
            _agiltasticDbEntities.SaveChanges();
        }
    }
}
